package com.redis.bloomfilter;

import org.redisson.Redisson;
import org.redisson.api.RBloomFilter;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;

/**
 * @author liyanhao
 * @Date 2023-02-14 21:57
 */
public class RedissonBloomFilter {
    public static void main(String[] args) {
        Config config = new Config();
        config.useSingleServer().setAddress("redis://192.168.139.30:6379").setPassword("123456");
        //构造Redisson
        RedissonClient redisson = Redisson.create(config);
        RBloomFilter<Object> bloomFilter = redisson.getBloomFilter("nameList");
        //初始化布隆过滤器 预计元素为100000000L 误差率3% 根据这个两个参数会计算出底层的bit数组大小
        bloomFilter.tryInit(100000000L, 0.03);
        //将zhangsan插入到布隆过滤器中
        bloomFilter.add("zhangsan");

        //判断下面号码是否存在布隆过滤器中
        System.out.println(bloomFilter.contains("guoji"));
        System.out.println(bloomFilter.contains("lisi"));
        System.out.println(bloomFilter.contains("zhangsan"));//true

    }
}
